/*
 * Created by JFormDesigner on Sun Jun 04 18:14:37 CST 2023
 */

package gui.admin;

import dao.ProductDao;
import entity.Product;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 * @author Liubuzhu
 */
public class AdminMainFrame extends JFrame {
    public AdminMainFrame() throws Exception {
        initComponents();
    }

    private void initComponents() throws Exception {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        menuBar1 = new JMenuBar();
        menu1 = new JMenu();
        manageProduct = new JMenuItem();
        addProduct = new JMenuItem();
        menu6 = new JMenu();
        manageSupplier = new JMenuItem();
        addSupplier = new JMenuItem();
        menu4 = new JMenu();
        manageUser = new JMenuItem();
        addUser = new JMenuItem();
        menu5 = new JMenu();
        manageCategory = new JMenuItem();
        addCategory = new JMenuItem();
        menu2 = new JMenu();
        managePurchase = new JMenuItem();
        addPurchase = new JMenuItem();
        menu3 = new JMenu();
        manageSale = new JMenuItem();
        label = new JLabel();
        label1 = new JLabel();
        label2 = new JLabel();


        //======== this ========
        setTitle("\u6b22\u8fce\u60a8\uff0c\u7ba1\u7406\u5458");
        setPreferredSize(new Dimension(600, 400));
        setVisible(true);
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //======== menuBar1 ========
        {

            //======== menu1 ========
            {
                menu1.setText("\u5546\u54c1\u7ba1\u7406");

                //---- manageProduct ----
                manageProduct.setText("\u5546\u54c1\u4fe1\u606f\u7ba1\u7406");
                menu1.add(manageProduct);

                manageProduct.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        try {
                            dispose();
                            ManageProductFrame manageProductFrame = new ManageProductFrame();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                });

                //---- addProduct ----
                addProduct.setText("\u6dfb\u52a0\u5546\u54c1\u4fe1\u606f");
                menu1.add(addProduct);

                addProduct.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        try {
                            dispose();
                            AddProductFrame addProductFrame = new AddProductFrame();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
            }
            menuBar1.add(menu1);

            //======== menu6 ========
            {
                menu6.setText("\u4f9b\u8d27\u5546\u7ba1\u7406");

                //---- manageSupplier ----
                manageSupplier.setText("供货商信息管理");
                menu6.add(manageSupplier);
                manageSupplier.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        dispose();
                        try {
                            ManageSupplierFrame manageSupplierFrame = new ManageSupplierFrame();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                });

                //---- addSupplier ----
                addSupplier.setText("添加供货商");
                menu6.add(addSupplier);

                addSupplier.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        dispose();
                        AddSupplierFrame addSupplierFrame = new AddSupplierFrame();
                    }
                });
            }
            menuBar1.add(menu6);

            //======== menu4 ========
            {
                menu4.setText("\u7528\u6237\u7ba1\u7406");

                //---- manageUser ----
                manageUser.setText("\u7528\u6237\u4fe1\u606f\u7ba1\u7406");
                menu4.add(manageUser);
                manageUser.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        dispose();
                        try {
                            dispose();
                            ManageUserFrame manageUserFrame = new ManageUserFrame();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                });

                //---- addUser ----
                addUser.setText("\u6dfb\u52a0\u7528\u6237\u4fe1\u606f");
                menu4.add(addUser);
                addUser.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        dispose();
                        AddUserFrame addUserFrame = new AddUserFrame();
                    }
                });
            }
            menuBar1.add(menu4);

            //======== menu5 ========
            {
                menu5.setText("\u5546\u54c1\u7c7b\u522b\u7ba1\u7406");

                //---- manageCategory ----
                manageCategory.setText("\u7c7b\u522b\u4fe1\u606f\u7ba1\u7406");
                menu5.add(manageCategory);

                manageCategory.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        try {
                            dispose();
                            ManageProductCategoryFrame manageProductCategoryFrame = new ManageProductCategoryFrame();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                });

                //---- addCategory ----
                addCategory.setText("\u6dfb\u52a0\u5546\u54c1\u7c7b\u522b");
                menu5.add(addCategory);

                addCategory.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        dispose();
                        AddProductCategoryFrame addProductCategoryFrame = new AddProductCategoryFrame();
                    }
                });
            }
            menuBar1.add(menu5);

            //======== menu2 ========
            {
                menu2.setText("\u8fdb\u8d27\u7ba1\u7406");

                //---- managePurchase ----
                managePurchase.setText("\u8fdb\u8d27\u4fe1\u606f\u7ba1\u7406");
                addPurchase.setText("入库商品");
                managePurchase.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        dispose();
                        try {
                            ManagePurchaseFrame managePurchaseFrame = new ManagePurchaseFrame();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
                menu2.add(managePurchase);
                menu2.add(addPurchase);
                addPurchase.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        dispose();
                        try {
                            AddPurchaseFrame addPurchaseFrame = new AddPurchaseFrame();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
            }
            menuBar1.add(menu2);

            //======== menu3 ========
            {
                menu3.setText("\u9500\u552e\u7ba1\u7406");

                //---- manageSale ----
                manageSale.setText("\u9500\u552e\u4fe1\u606f\u7ba1\u7406");
                menu3.add(manageSale);
                manageSale.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        try {
                            dispose();
                            ManageSaleFrame manageSaleFrame = new ManageSaleFrame();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
            }
            menuBar1.add(menu3);
        }
        setJMenuBar(menuBar1);

        ProductDao productDao = new ProductDao();

        float totalSalePrice = productDao.getSaleTotalPrice();
        float totalPurchasePrice = productDao.getPurchaseTotalPrice();
        float totalProfit = totalSalePrice - totalPurchasePrice;
        label.setText("当前总利润是：" + totalProfit + "元！！！");
        label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
        contentPane.add(label);
        label.setBounds(160, 100, 400, 50);

        label1.setText("进货总花费：" + totalPurchasePrice + "元");
        label1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
        contentPane.add(label1);
        label1.setBounds(160, 160, 400, 50);

        label2.setText("销售总额：" + totalSalePrice + "元");
        label2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
        contentPane.add(label2);
        label2.setBounds(160, 220, 400, 50);

        //添加背景图片
        JLabel background = new JLabel(new ImageIcon("./image/admin/管理员背景.jpg"));
        background.setBounds(0, 0, 600, 400);
        this.getContentPane().add(background);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JMenuBar menuBar1;
    private JMenu menu1;
    private JMenuItem manageProduct;
    private JMenuItem addProduct;
    private JMenu menu6;
    private JMenuItem manageSupplier;
    private JMenuItem addSupplier;
    private JMenu menu4;
    private JMenuItem manageUser;
    private JMenuItem addUser;
    private JMenu menu5;
    private JMenuItem manageCategory;
    private JMenuItem addCategory;
    private JMenu menu2;
    private JMenuItem managePurchase;
    private JMenuItem addPurchase;
    private JMenu menu3;
    private JMenuItem manageSale;
    private JLabel label;
    private JLabel label1;
    private JLabel label2;

    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
    public static void main(String[] args) throws Exception {
        AdminMainFrame adminMainFrame = new AdminMainFrame();
    }
}
